#include <vector>
using namespace std;
class Solution {
public:
    int maxValue(vector<vector<int>>& grid) {
        vector<vector<int>> board=grid;
        int m=board.size(),n=board[0].size();
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(i==0&&j==0) continue;
                if(i==0) board[i][j]+=board[i][j-1];
                else if(j==0) board[i][j]+=board[i-1][j];
                else board[i][j]+=max(board[i][j-1],board[i-1][j]);
            }
        }
        return board[m-1][n-1];
    }
};